<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <!-- 搜索表单 -->
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          label-width="68px"
        >
          <el-form-item label="编号" prop="saleNo">
            <el-input
              v-model="queryParams.saleNo"
              placeholder="请输入订单编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="状态" prop="categoryId">
            <el-select
              v-model="queryParams.status"
              size="small"
              placeholder="请选择"
            >
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

      

        <!-- 数据展示Table -->
        <el-table
          v-loading="loading"
          :data="dataList"
        >
          <el-table-column label="ID" align="center" prop="saleId" width="50" />
          <el-table-column label="订单编号" align="center" prop="saleNo" />
          <el-table-column
            label="订单明细"
            align="center"
            prop="saleItemVoList"
          >
            <template slot-scope="scope">
              <div
                v-for="(item, index) in scope.row.saleItemVoList"
                :key="index"
                class="itemDetails"
              >
                <div>产品编号： {{ item.itemSn }}</div>
                <div>产品名称： {{ item.productName }}</div>
                <div>产品价格： {{ item.price }}</div>
                <div>购买数量： {{ item.quantity }}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="订单时间" sortable align="center" prop="saleTime" />
          <el-table-column label="订单状态" align="center" prop="status">
            <template slot-scope="scope">
              <el-tag
                v-if="scope.row.status === '已付款'"
                size="small"
                type="success"
                >已付款</el-tag
              >
              <el-tag
                v-else-if="scope.row.status === '已预定'"
                size="small"
                type="normal"
                >已预定</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column
            label="价格"
            align="center"
            prop="total"
            width="55"
          />
        
        </el-table>

        <!-- 分页加载 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryParams.current"
          :page-sizes="[5, 10, 20, 50]"
          :page-size="queryParams.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { getOrder } from "@/api/order";
import SingleUpload from "@/components/upload/singleUpload";

export default {
  name: "ProductView",
  components: {
    SingleUpload,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表格数据
      dataList: [],
      // 查询参数
      // 查询参数
      queryParams: {
        current: 1,
        pageSize: 10,
        sortField: "create_time",
        sortOrder: "ascend",
      },
      // 下拉框类别选项数据
      statusOptions: [
        {
          value: "已付款",
          label: "已付款",
        },
        {
          value: "已预定",
          label: "已预定",
        },
      ],
      // 尺寸数据
      sizeOptions: [
        { id: 1, value: "XS" },
        { id: 2, value: "S" },
        { id: 3, value: "M" },
        { id: 4, value: "L" },
        { id: 5, value: "XL" },
        { id: 6, value: "XXL" },
      ],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单
      form: {},
      // 表单校验
      rules: {
        productSn: [
          { required: true, message: "编号不能为空", trigger: "blur" },
        ],
        productName: [
          { required: true, message: "名称不能为空", trigger: "blur" },
        ],
      },
      // 总条数
      total: 0,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      getOrder(this.queryParams).then((response) => {
        this.dataList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.queryForm.resetFields();
      this.queryParams.status = ""
      delete this.queryParams.status
      this.getList();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const productId = row.id || this.ids;
      this.$confirm('是否确认删除ID为"' + productId + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delProduct({ id: productId });
        })
        .then(() => {
          this.getList(); // 刷新数据
          this.$message.success("删除成功");
        })
        .catch(() => {});
    },

    /** 表单重置 */
    resetForm() {
      // 可进行数据初始化工作
      this.form = {
        size: "",
        id: "",
        name: "",
        price: "",
        categoryId: "",
        color: "",
      };
    },

   
    /** 处理分页 */
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.current = val;
      this.getList();
    },
  },
};
</script>

<style scoped>
.itemDetails {
  margin-bottom: 10px;
  padding: 3px;
  border-bottom: 1px solid rgb(162, 158, 158);
}

.itemDetails div{
  display: flex;
  justify-content: space-between;
}
</style>